function Timer(obj) {
    this.runTime = null;
    this.is_onstart = true; //是否点击开始
    this.is_onstop = false; //是否点击暂停
    this.count = 0; //点击开始的次数
    this.sstart = 0; //记录暂停时的毫秒数
    this.obj = obj; //记录输出对象
		this.n = 0;	// 毫秒
		this.s = 0;	// 秒
		this.m = 0; // 分钟
		this.interval = 100; //每100毫秒刷新一次
}

Timer.prototype.start = function () {
    
    let start = Date.now(); //每次点击开始重置开始时间
    this.count++;
    this.is_onstart = true;
    //is_onstop=false;
    let that = this;
    if (this.is_onstart && (this.count == 1)) {
        this.runTime = setTimeout(step, that.interval);

        function step() {
            let msecond = (Date.now() - start) + that.sstart; //现在时间-开始时间+之前暂停时记录的时间  单位毫秒
            that.s = Math.floor(msecond / 1000);
            that.n = Math.floor((msecond % 1000) / 10);
            // n = msecond % 1000;  显示三位
            that.m = Math.floor(msecond / 60000);
            that.outputTime();
            // console.log("behind");
            // console.log(s+":"+n+" :"+msecond);
            if (that.is_onstart) {
                setTimeout(step, that.interval);
            } else if (that.is_onstop) {
                that.sstart = msecond;
                clearTimeout(that.runTime);
            } else{
                that.outputTime("00:00:00");  //当reset时覆盖最后一次显示结果
                // console.log("last");
            }
        }
    }
}

//暂停
Timer.prototype.stop = function () {
    this.is_onstart = false;
    this.is_onstop = true;
    this.count = 0;
}

//重置
Timer.prototype.reset = function () {
    clearTimeout(this.runTime);
    this.runTime = null;
    this.is_onstart = false;
    this.is_onstop = false;
    this.count = 0;
    this.sstart = 0;
		this.s = 0;
    this.outputTime("00:00:00");
    // console.log("before");
}

//输出
Timer.prototype.outputTime = function () {
	this.obj[0].innerHTML = toDub(this.m % 60);
	this.obj[1].innerHTML = toDub(this.s % 60);
	this.obj[2].innerHTML = toDub(this.n);
}

//补零
function toDub(n) {
    return n < 10 ? "0" + n : "" + n;
}
